// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2008-7-6 19:10:19
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   CreateStrutsEditMap.java

package com.creawor.generator;

import java.io.*;

// Referenced classes of package com.creawor.generator:
//            Config_bean, Sql_and_java_map

public class CreateStrutsEditMap
{

    public CreateStrutsEditMap(String table_nameP)
    {
        cb = new Config_bean();
        table_name = "";
        pojo_table_name = "";
        table_name = table_nameP.toLowerCase();
        pojo_table_name = table_nameP;
        map = new Sql_and_java_map(table_nameP);
    }

    public void writefile()
    {
        Config_bean _tmp = cb;
        Config_bean _tmp1 = cb;
        String pathname = (new StringBuilder(String.valueOf(Config_bean.path_name_j2src))).append("/").append(Config_bean.package_name.replace('.', '/')).append("/").append(table_name).append("/").toString();
        String Filename = (new StringBuilder(String.valueOf(table_name))).append("_EditMap.java").toString();
        //System.out.println((new StringBuilder("\n")).append(pathname).append(Filename).toString());
        try
        {
            File p = new File(pathname);
            if(!p.exists() || !p.isDirectory())
                p.mkdirs();
            PrintWriter pw = new PrintWriter(new FileOutputStream((new StringBuilder(String.valueOf(pathname))).append(Filename).toString()));
            pw.println(getBeanCode());
            pw.close();
            //System.out.println((new StringBuilder("\nEditMap\u4EE3\u7801\u6210\u529F\u751F\u6210:\n")).append(pathname).append(Filename).toString());
        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
    }

    public String getHead()
    {
        Config_bean _tmp = cb;
        String str_tmp = (new StringBuilder("\n//\u7531\u751F\u6210\u5668\u751F\u6210\npackage ")).append(Config_bean.package_name).append(".").append(table_name).append(";\n").append("import net.sf.hibernate.HibernateException;\n").append("import net.sf.hibernate.Session;\n").append("import net.sf.hibernate.Hibernate;\n").append("import net.sf.hibernate.LockMode;\n").append("//import oracle.sql.CLOB;\n").append("import com.creawor.imei.base.AbsEditMap;\n\n").append("public class ").append(table_name).append("_EditMap extends AbsEditMap {\n\n").toString();
        return str_tmp;
    }

    public String getBody()
    {
        String str_tmp = (new StringBuilder("public void add(")).append(table_name).append("_Form vo) throws HibernateException {\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append(pojo_table_name).append(" po=new ").append(pojo_table_name).append("();\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append(map.vo2po_Copy()).append("\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\t\tSession session = this.beginTransaction();\n").append("try {\n").append("\tsession.save(po);\n").append(map.clob_blob_add_code).append("\tthis.endTransaction(true);\n").append("} catch (Exception e) {\n").append("\tthis.endTransaction(false);\n").append("\te.printStackTrace();\n").append("   throw new HibernateException(e);").append("}\t\n}\n\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("public void delete(").append(table_name).append("_Form vo) throws HibernateException {\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("String id = vo.getId();\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("delete(id);\n}\n\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("public void delete(String id) throws HibernateException {\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("Session session = this.beginTransaction();\ntry{\n ").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append(pojo_table_name).append(" po =(").append(pojo_table_name).append(") session.load(").append(pojo_table_name).append(".class, new Integer(id));\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append(" session.delete(po);\n").append(" this.endTransaction(true);\n").append("} catch (HibernateException e) {\n").append("  e.printStackTrace();\n  this.endTransaction(false);\n").append("}\n}\n\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("public void update(").append(table_name).append("_Form vo) throws HibernateException {\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("\tSession session = this.beginTransaction();\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append("   String id = vo.getId();\n   ").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append(pojo_table_name).append(" po =(").append(pojo_table_name).append(") session.load(").append(pojo_table_name).append(".class, new Integer(id));\n").toString();
        str_tmp = (new StringBuilder(String.valueOf(str_tmp))).append(map.vo2po_Copy()).append("\n").append("try {\n").append("\tsession.update(po);\n").append(map.clob_blob_add_code).append("\tthis.endTransaction(true);\n").append("} catch (Exception e) {\n").append("\tthis.endTransaction(false);\n").append("\te.printStackTrace();\n").append("   throw new HibernateException(e);").append("  }\n}\n\n").toString();
        return str_tmp;
    }

    public String getFoot()
    {
        return "}\n//\u7531\u751F\u6210\u5668\u751F\u6210";
    }

    public String getBeanCode()
    {
        return (new StringBuilder(String.valueOf(getHead()))).append(getBody()).append(getFoot()).toString();
    }

    Config_bean cb;
    public String table_name;
    public String pojo_table_name;
    public Sql_and_java_map map;
}